<template>
  <li>
    <label v-if="$parent.$parent.editId !== todo.id">
      <input
        type="checkbox"
        :checked="todo.isDone"
        @change="$bus.$emit('updateTodo', todo.id)"
      />
      <span :class="todo.isDone ? 'done' : ''">{{ todo.todoName }}</span>
    </label>
    <input type="text" v-else />
    <button class="btn btn-danger">删除</button>
    <button class="btn btn-edit" @click="handle">编辑</button>
  </li>
</template>

<script>
export default {
  props: ['todo'],
  methods: {
    handle() {
      this.$parent.$parent.editId = this.todo.id
    },
  },
}
</script>

<style>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  display: flex;
  align-items: center;
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}

.done {
  text-decoration: line-through;
  color: #ccc;
}
</style>
